Technical Q&A JAVA29
Creating Mac OS X applications from Java JAR files


Q: How do I create a double-clickable Java application?

A: MRJAppBuilder builds applications out of Java JAR files into the application bundle format. In order to build your application, you must specify (at a minimum) the main class name, the classpath, and the location of the output file. Each of these values is settable from within the Application panel.

Build Java Application

The main class field is a text field where you must enter the name of the main class. This field represents the value of the property com.apple.mrj.application.main. Remember to include any package information, such as com.foo.myclass.

The classpath is also a text field where you must enter the classpath. This field represents the value of the property com.apple.mrj.application.classpath. In the following example, MyJarFile.jar and MoreClasses.jar reside in the same directory as the application. The "../" is required because classpath elements are determined relative to the application's folder, not the application's parent folder.

../MyJarFile.jar:../MoreClasses.jar

The last required field is the output file field. You must specify the name and location of the output file. You may either enter the path in the text field provided or you may choose the "Set..." button to set the location of the output file using the file chooser dialog.

Using the other tabbed panels is optional. The Mac OS X panel allows you to set values specific to the Mac OS X application bundle format. If you do not specify the CFBundleExecutable or CFBundleName, they will be set based on the name of the output file you choose.

The Java Properties panel allows you to set Java runtime properties. The main and classpath fields are not editable; they can only be set in the Application panel. The remaining properties are the standard properties supported by Java on Mac OS along with their default values. To set additional properties not listed in the table, simply add them to the end of the list. In previous versions of MRJAppBuilder, you were required to create a configurations file defining the Java runtime properties. This panel is a replacement for the configurations file.

The Merge Files panel provides a means for adding .zip or .jar files to the application. Choose the "Add..." button to add files to the list. Each item added to the merge list will be copied into the application's Contents/Resources/Java/ directory. For each item you add to the merge list, you must also add that element to the classpath. In this release, items merged into the application are not automatically added to the classpath. For example, if you were to add the file MyJarFile.jar using the Merge Files panel, then the above classpath example would need to become:

Contents/Resources/Java/MyJarFile.jar:../MoreClasses.jar

Application resources such as images or any other file that would be expected to be in the Java applications directory should be located in the same folder as the application bundle.


Note:
If you are using ProjectBuilder to build your applications from Java source, it will create a double-clickable application for you. It is not necessary to use MRJAppBuilder.



Warning:
MRJAppBuilder will not warn you if the output file already exists. It will just overwrite the existing application and replace it with a new copy.


[Dec 21 2001]


Developer Documentation | Technical Notes | Development Kits | Sample Code